/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sadhar.sipp.jenispos;

import org.sadhar.sia.framework.ClassApplicationModule;
import org.sadhar.sipp.jenispos.JenisPos;
import org.sadhar.sipp.jenispos.JenisPosDAO;
import org.sadhar.sipp.jenispos.JenisPosDAOImpl;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Radio;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 *
 * @author hendro
 */
public class JenisPosPopupWnd extends ClassApplicationModule {

    private Textbox txtboxKeySearch;
    private Listbox lstboxJenisPos;
    private JenisPosDAO jenisPosDAO;

    public JenisPosPopupWnd() {
        this.jenisPosDAO = new JenisPosDAOImpl();
    }

    public void onCreate() throws Exception {
        txtboxKeySearch = (Textbox) getFellow("txtboxKeySearch");
        lstboxJenisPos = (Listbox) getFellow("lstboxJenisPos");
        load();
    }

    public void load() throws Exception {
        lstboxJenisPos.getItems().clear();
        int no = 1;
        for (JenisPos pos : jenisPosDAO.list(txtboxKeySearch.getValue().toString())) {
            Listitem item = new Listitem();
            item.setValue(pos);
            item.appendChild(new Listcell("" + no++));
            item.appendChild(new Listcell(pos.getJenisPos().toString()));
            lstboxJenisPos.appendChild(item);
        }
    }

    public void lstboxJenisPosOnSelect() throws Exception {
        Window window = (Window) this.getRoot().getFellow("contentDiv").getFirstChild();
        Textbox txtboxNamaTabel = (Textbox) window.getFellow("txtboxNamaTabel");
        Textbox txtboxCariJenisPos = (Textbox)window.getFellow("txtboxCariJenisPos");
        Textbox txtboxKodeGL1 = (Textbox)window.getFellow("txtboxKodeGL1");
        Textbox txtboxKodeGL2 = (Textbox)window.getFellow("txtboxKodeGL2");
        Textbox txtboxKodeGL3 = (Textbox)window.getFellow("txtboxKodeGL3");
        Textbox txtboxKodeGL4 = (Textbox)window.getFellow("txtboxKodeGL4");
        Combobox cmbboxKelompokPengurusBiaya = (Combobox)window.getFellow("cmbboxKelompokPengurusBiaya");
        Radio rdTidak = (Radio)window.getFellow("rdTidak");
        Radio rdYa = (Radio)window.getFellow("rdYa");
        JenisPos pos = (JenisPos) lstboxJenisPos.getSelectedItem().getValue();
        if(pos.getNamaTabelSubPos().equalsIgnoreCase("posBiaya")){
            txtboxKodeGL1.setDisabled(true);
            txtboxKodeGL2.setDisabled(true);
            txtboxKodeGL3.setDisabled(true);
            txtboxKodeGL4.setDisabled(true);
            cmbboxKelompokPengurusBiaya.setDisabled(false);
        }else{
            txtboxKodeGL1.setDisabled(false);
            txtboxKodeGL2.setDisabled(false);
            txtboxKodeGL3.setDisabled(false);
            txtboxKodeGL4.setDisabled(false);
            cmbboxKelompokPengurusBiaya.setDisabled(true);
        }
        if(pos.getNamaTabelSubPos().equalsIgnoreCase("posPendapatan")){
            rdTidak.setDisabled(false);
            rdYa.setDisabled(false);
        }else{
            rdTidak.setDisabled(true);
            rdYa.setDisabled(true);
            rdTidak.setSelected(false);
            rdYa.setSelected(false);
        }
        txtboxNamaTabel.setValue(pos.getNamaTabelSubPos());
        txtboxCariJenisPos.setValue(pos.getJenisPos());
        this.detach();
    }
}
